#!/usr/bin/env bash
# Build the entire core package as required by Android App
set -e
if [ -z "$O3" ]; then
    echo O3 var must point to ovpn3 tree
    exit 1
fi

[ -z "$ECHO" ] && ECHO=0

if [ "$ECHO" -eq 0 ]; then
    exec > $O3/android_build.log
    exec 2>&1
fi

[ -z "$DEP_DIR" ] && export DEP_DIR=${O3}/deps
[ -z "$DL" ] && export DL=~/dl

mkdir -p $DEP_DIR
mkdir -p $DL

export NO_MOD_PATH=1
. $O3/core/vars/android-sdk-path

echo BUILD ANDROID SDK
$O3/core/scripts/android/build-sdk

echo BUILD TOOLCHAIN
$O3/core/scripts/android/build-toolchain

echo BUILD DEPS
cd $DEP_DIR
rm -rf asio* lz4* mbedtls* #lzo* boost* minicrypto openssl* polarssl* snappy*
echo "******* ASIO"
$O3/core/deps/asio/build-asio
echo "******* MBEDTLS"
$O3/core/scripts/android/build-mbedtls
echo "******* LZ4"
$O3/core/scripts/android/build-lz4

#echo "******* BOOST"
#$O3/core/scripts/android/build-boost
#echo "******* MINICRYPTO"
#$O3/core/scripts/android/build-minicrypto
#echo "******* OpenSSL"
#$O3/core/scripts/android/build-openssl-small
#echo "******* LZO"
#$O3/core/scripts/android/build-lzo
#echo "******* SNAPPY"
#$O3/core/scripts/android/build-snappy

echo BUILD CORE LIBRARY
$O3/core/javacli/build-android

echo DONE.
